home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK1.toast / Development Kits (Disc 1) / Apple Shared Library Manager / ASLM Examples / Example Tools / Sources / TTimeExample.cp < prev    next >
Encoding:
Text File  |  1996-11-19  |  1.9 KB  |  65 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        TTimeExample.cp
  3.  
  4.     Contains:    This module shows an example of how to use the TTime subclass.
  5.  
  6.     Copyright:    © 1993 by Apple Computer, Inc., all rights reserved.
  7.  
  8. */
  9.  
  10. #include "TInitSLM.h"            // the TInitSLM class and SLM include files
  11.  
  12. /*————————————————————————————————————————————————————————————————————————————————————
  13.     main 
  14.  
  15.     This examples uses a TTimeStamp to get the current the time, and then displays
  16.     that time. It also uses the TStopWatch class to create delays of 4 seconds,
  17.     2 seconds, and 1 second.
  18. ————————————————————————————————————————————————————————————————————————————————————*/
  19.  
  20. main() 
  21. {
  22.     TInitSLM initLibraryManager;            // initialize the shared library manager
  23.     
  24.     if( initLibraryManager.Failed() )        // If we failed, let's go home
  25.         return 1;
  26.  
  27.                 // --------- example of TTimeStamp --------- 
  28.     
  29.     TTimeStamp        *timestamp = new TTimeStamp;
  30.     
  31.     if( !timestamp ) return 1;        // make sure we didn't fail
  32.     
  33.     cout << "Time stamped at " << timestamp->GetMicroseconds() << " µsec\n" << endl;
  34.     cout << "Time stamped at " << timestamp->GetMilliseconds() << " msec\n" << endl;
  35.     cout << "Time stamped at " << timestamp->GetSeconds()      << " sec\n" << endl;
  36.  
  37.     delete timestamp;                        // we are done with stopwatch
  38.     
  39.                 // --------- example of TStopwatch --------- 
  40.         
  41.     TStopwatch        *stopwatch = new TStopwatch;
  42.  
  43.     if( !stopwatch ) return 1;                // make sure we didn't fail
  44.         
  45.     cout << "waiting for 4000000 microseconds" << endl;
  46.     stopwatch->Reset();
  47.     while( stopwatch->ElapsedMicroseconds() < 4000000 );
  48.     cout << "done *********" << endl;
  49.     
  50.     cout << "waiting for 2000 milliseconds" << endl;
  51.     stopwatch->Reset();
  52.     while( stopwatch->ElapsedMilliseconds() < 2000 );
  53.     cout << "done *********" << endl;
  54.  
  55.     cout << "waiting for 1 second" << endl;
  56.     stopwatch->Reset();
  57.     while( stopwatch->ElapsedSeconds() < 1 );
  58.     cout << "done *********" << endl;
  59.  
  60.     delete stopwatch;                        // we are done with TimeStamp
  61.  
  62.     return 0;
  63. }
  64.  
  65.